QuickStart: Playing with a Poppy Ergo (or a PoppyErgoJr)

This notebook is still work in progress! Feedbacks are welcomed!

In this tutorial we will show how to get started with your PoppyErgo creature. You can use a PoppyErgoJr instead.

To run the code in this notebook, you will need:

You can install those libraries with the pip tool (see here if you don't know how to run this):

pip install pypot poppy-ergo

Connect to your robot

For a PoppyErgo:


In [1]:
from poppy.creatures import PoppyErgo

In [2]:
ergo = PoppyErgo()

For a PoppyErgoJr:


In [ ]:
from poppy.creatures import PoppyErgoJr

ergo = PoppyErgoJr()

Get robot current status


In [3]:
ergo


Out[3]:
<Robot motors=[<DxlMotor name=m1 id=11 pos=-1.69>, <DxlMotor name=m2 id=12 pos=-97.13>, <DxlMotor name=m3 id=13 pos=89.96>, <DxlMotor name=m4 id=14 pos=0.65>, <DxlMotor name=m5 id=15 pos=41.5>, <DxlMotor name=m6 id=16 pos=22.14>]>

In [4]:
ergo.m2


Out[4]:
<DxlMotor name=m2 id=12 pos=-97.43>

In [5]:
ergo.m2.present_position


Out[5]:
-97.13

In [6]:
ergo.m2.present_temperature


Out[6]:
32.0

In [7]:
for m in ergo.motors:
    print 'Motor "{}" current position = {}'.format(m.name, m.present_position)


Motor "m1" current position = -1.69
Motor "m2" current position = -97.13
Motor "m3" current position = 89.96
Motor "m4" current position = 0.65
Motor "m5" current position = 41.5
Motor "m6" current position = 22.14

Turn on/off the compliancy of a motor


In [8]:
ergo.m3.compliant


Out[8]:
True

In [9]:
ergo.m6.compliant = False

Go to the zero position


In [10]:
ergo.m6.goal_position = 0.

In [11]:
for m in ergo.motors:
    m.compliant = False
    
    # Goes to the position 0 in 2s
    m.goto_position(0, 2)

In [ ]:
# You can also change the maximum speed of the motors
# Warning! Goto position also change the maximum speed.

for m in ergo.motors:
    m.moving_speed = 50

Make a simple dance movement

On a single motor:


In [13]:
import time

ergo.m4.goal_position = 30
time.sleep(1.)
ergo.m4.goal_position = -30

On multiple motors:


In [14]:
ergo.m4.goal_position = 30
ergo.m5.goal_position = 20
ergo.m6.goal_position = -20

time.sleep(1.)

ergo.m4.goal_position = -30
ergo.m5.goal_position = -20
ergo.m6.goal_position = 20

Wrap it inside a function for convenience:


In [15]:
def dance():
    ergo.m4.goal_position = 30
    ergo.m5.goal_position = 20
    ergo.m6.goal_position = -20

    time.sleep(1.)

    ergo.m4.goal_position = -30
    ergo.m5.goal_position = -20
    ergo.m6.goal_position = 20
    
    time.sleep(1.)

In [16]:
dance()

In [17]:
for _ in range(4):
    dance()

Using goto position instead:


In [18]:
def dance2():
    ergo.goto_position({'m4': 30, 'm5': 20, 'm6': -20}, 1., wait=True)
    ergo.goto_position({'m4': -30, 'm5': -20, 'm6': 20}, 1., wait=True)

In [19]:
for _ in range(4):
    dance2()